Loading
notes intro/old submit AP Problems the dump links
 

Create a simply integer class called EasyInt that will keep track of one integer:

  • so have a global int variable
  • have two constructors:
    • a. with no paramater such that when constructed have its value automatically set to 0
    • b. with one parameter where when constructed have its value set to the parameter
  • have a method called setValue that will take in a number and set the global value to that
  • have a method called getValue
  • have a method called isEven which will return true or false
  • have a method called toString

Add these methods:

//The method adds 5 to x
	public static void add5toIntValue (int m)
	{
		m=m+5;
		System.out.println("m is " + m);      
	}

//The method adds 5 to x
	public static void add5toObjValue (EasyInt m)
	{
		m.setValue(10);
		System.out.println("m is " + m);      
	}
	
	//public static void main (String args[])
	{
	
	
	}
	


 

 

Now try predicting the output here.

 

Lets play with references. Try this worksheet out.

 

What did you learn?

 

Now lets try with this code: